﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;

namespace BaoVeBienCuong.Playgame.maps
{
    public class Map
    {
        int[,] map; // map hiện hành
        Vector2 size; // kích thước ma trận của map
        float scale; // thuộc tính căn chỉnh
        Texture2D[] images = new Texture2D[16]; // các ảnh chứa map
        public Vector2 sizeimages;//kich thuoc ban do
        public Vector2 sizeImage;//kich thuoc moi anh
        Random rand;
        public bool isCau;
        Texture2D cauimage;
        int level;
        MapFolder.Map mapnew;
        public Map(int level, ContentManager content)
        {
            mapnew = new MapFolder.Map(content);
            isCau = false;
            setLevel(level);
            switch (this.level)
            {
                case 0:
                    {
                        #region
                        size = new Vector2(10, 18);
                        map = new int[10, 18]
                            {
                                {2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                                {2,2,1,0,2,2,0,2,2,0,2,2,2,2,0,0,2,2},
                                {2,0,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,2},
                                {2,0,1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,2},
                                {2,0,1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,2},
                                {2,0,1,1,1,1,1,1,0,0,0,0,0,0,1,0,0,2},
                                {2,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,2},
                                {2,0,0,0,0,2,2,2,0,0,0,0,0,0,1,1,1,1},
                                {2,2,2,0,0,2,2,2,0,0,0,0,0,0,0,0,2,2},
                                {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}
                            };
                        break;
                        #endregion
                    }
                case 1:
                    {
                        #region
                        size = new Vector2(12, 21);
                        map = new int[12, 21]
                            {
                                {2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2},
                                {2,0,1,0,2,0,0,0,0,0,0,0,0,0,0,2,0,2,1,0,2},
                                {2,0,1,2,0,0,0,0,1,1,1,1,1,0,0,0,0,2,1,0,2},         
                                {2,0,1,0,2,2,0,0,1,0,1,0,1,0,0,0,2,2,1,0,2},
                                {2,0,1,0,0,0,0,0,1,0,1,0,1,0,0,0,0,0,1,0,2},
                                {2,0,1,2,0,0,0,0,1,0,1,0,1,0,0,0,0,0,1,0,2},
                                {2,0,1,2,0,0,0,0,1,0,1,0,1,0,0,0,0,0,1,0,2},
                                {2,0,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,0,2},
                                {2,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,2},
                                {2,2,2,0,0,0,0,0,0,0,1,0,0,0,0,0,0,2,0,0,2},
                                {2,2,2,0,2,2,0,0,2,0,1,0,2,2,2,2,2,2,2,2,2},
                                {2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,2}
                            };
                        break;
                        #endregion
                    }
                case 2:
                    {
                        #region
                        size = new Vector2(12, 24);
                        map = new int[12, 24]
                            {
                                {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                                {2,2,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1},
                                {2,2,1,0,0,0,0,0,0,0,2,1,0,0,0,2,2,0,0,0,1,0,0,2},
                                {2,2,1,0,0,2,2,2,2,0,0,1,0,0,2,2,2,2,0,0,1,0,0,2},
                                {2,2,1,0,0,2,0,0,2,0,0,1,0,0,2,2,2,2,0,0,1,0,0,2},
                                {2,0,1,0,2,2,2,2,2,0,0,1,0,0,2,2,2,2,0,0,1,0,0,2},
                                {2,0,1,0,2,0,0,0,0,0,2,1,0,0,0,2,2,0,0,0,1,0,0,2},
                                {2,0,1,0,0,0,0,0,0,0,2,1,0,0,0,0,0,0,0,0,1,0,0,2},
                                {2,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                                {2,0,1,0,0,0,0,0,0,0,2,1,2,0,0,0,0,0,0,0,1,0,0,2},
                                {2,0,1,0,2,0,0,2,2,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2},
                                {2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}
                            };
                        break;
                        #endregion
                    }
                case 3:
                    {
                        #region
                        size = new Vector2(14, 21);
                        map = new int[14, 21]
                            {
                                {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                                {2,0,0,0,0,0,0,0,2,0,0,2,2,2,2,2,0,0,0,2,2},         
                                {2,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,2},         
                                {2,0,0,1,0,0,0,0,0,0,0,2,2,2,2,2,0,1,0,0,2},
                                {2,0,0,1,0,0,0,0,0,2,2,2,2,2,2,2,0,1,0,0,2},
                                {2,0,0,1,0,0,0,0,0,0,2,2,2,2,2,2,0,1,0,0,2},
                                {1,1,1,1,0,0,0,0,0,0,2,2,2,2,2,2,0,1,1,1,1},
                                {2,0,0,1,0,0,0,0,0,2,2,2,2,2,2,2,0,1,0,0,2},
                                {2,0,0,1,0,0,0,0,0,0,2,2,2,2,2,2,0,1,0,0,2},
                                {2,0,0,1,0,0,0,0,0,0,2,2,2,2,2,2,0,1,0,0,2},
                                {2,0,0,1,0,0,0,0,0,0,0,2,2,2,2,2,0,1,0,0,2},
                                {2,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,2},
                                {2,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,0,0,0,0,2},
                                {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}
                            };
                        break;
                        #endregion
                    }
                case 4:
                    {
                        #region
                        size = new Vector2(14, 23);
                        map = new int[14, 23]
                            {
                                {2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                                {2,0,2,1,2,0,0,2,2,0,0,0,0,0,0,0,0,0,0,0,2,0,2},         
                                {2,0,2,1,2,0,0,2,2,0,0,0,0,0,0,0,0,0,0,0,2,0,2},         
                                {2,0,2,1,2,0,0,2,2,0,0,0,0,0,0,0,0,0,0,0,2,0,2},
                                {2,0,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2},
                                {2,0,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,0,2},
                                {2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,0,2},
                                {2,0,0,0,0,0,0,0,0,0,0,0,2,2,0,0,0,0,2,1,2,0,2},
                                {2,0,2,0,0,0,0,0,0,0,0,0,2,2,0,0,0,0,2,1,2,0,2},
                                {2,2,0,0,0,0,0,0,0,0,0,0,2,2,0,0,0,0,2,1,2,0,2},
                                {2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,2,2,2},
                                {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2},
                                {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2},
                                {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}
                            };
                        break;
                        #endregion
                    }
                case 5:
                    {
                        #region
                        size = new Vector2(18, 18);
                        map = new int[18, 18]
                            {
                                {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                                {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2}, 
                                {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2},
                                {2,2,0,0,0,0,0,0,2,2,2,0,0,0,2,2,1,2},
                                {2,2,2,0,0,0,0,0,2,2,2,0,0,0,2,2,1,2},
                                {2,0,2,0,0,0,0,0,2,2,0,0,0,0,2,2,1,2},
                                {2,0,2,2,0,0,2,1,1,1,1,1,1,0,2,2,1,2},
                                {2,0,0,0,0,0,0,1,2,0,0,0,1,0,2,2,1,2},
                                {2,0,0,0,0,0,0,1,2,0,0,0,1,0,2,2,1,2},
                                {2,0,0,0,0,0,0,1,2,2,2,2,1,2,2,2,1,2},
                                {2,0,0,0,0,0,2,1,1,1,1,1,1,1,1,1,1,2},
                                {2,0,0,2,2,0,0,0,0,0,0,0,1,0,0,0,0,2},
                                {2,0,0,2,2,0,0,0,2,0,0,0,1,0,0,0,0,2},
                                {2,0,0,2,2,0,0,0,2,0,0,0,1,0,0,0,0,2},
                                {2,0,0,0,0,0,0,0,2,0,0,0,1,0,0,0,2,2},
                                {2,2,0,0,0,0,0,0,2,0,0,0,1,1,1,1,1,1},
                                {2,2,0,0,0,0,0,0,2,2,2,2,0,0,0,0,2,2},
                                {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}
                            };
                        break;
                        #endregion
                    }
                case 6:
                    {
                        #region
                        size = new Vector2(24, 24);
                        map = new int[24, 24]
                            {
                                {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                                {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                                {2,2,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2},
                                {2,0,0,2,0,0,0,2,0,2,0,0,0,0,0,2,2,0,0,0,2,0,0,0},
                                {2,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
                                {2,0,1,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,1,0,0},
                                {2,0,1,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,1,0,0},
                                {0,0,1,2,2,0,2,2,0,0,2,1,2,0,0,2,2,2,0,2,2,1,0,0},
                                {0,0,1,2,2,2,2,0,0,0,2,1,2,0,0,0,2,2,2,2,2,1,0,0},
                                {0,0,1,2,2,2,2,2,0,0,0,1,0,0,0,2,2,2,2,2,2,1,0,0},
                                {0,0,1,2,2,2,2,2,0,0,0,1,0,0,0,2,2,2,2,2,2,1,0,0},
                                {0,0,1,2,2,0,2,0,0,0,0,1,0,0,0,0,2,2,0,2,2,1,0,0},
                                {0,0,1,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,1,0,0},
                                {0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0},
                                {0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,2},
                                {0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,2},
                                {0,0,1,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,1,0,2},
                                {0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,2},
                                {0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0},
                                {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
                                {0,2,0,0,0,0,0,2,1,2,2,2,0,2,2,1,2,0,0,0,0,0,2,2},
                                {2,2,0,0,0,0,2,2,1,2,2,2,0,0,2,1,2,2,2,0,0,0,0,0},
                                {2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2},
                                {2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2}
                            };
                        break;
                        #endregion
                    }
                case 7:
                    {
                        #region
                        isCau = true;
                        size = new Vector2(12, 24);
                        map = new int[12, 24]
                            {
                                {0,0,0,0,1,0,0,0,0,0,2,2,2,0,0,0,2,2,2,2,2,0,1,0},
                                {2,0,0,0,1,0,0,0,0,0,2,2,2,0,2,0,0,2,2,2,2,0,1,0},
                                {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,1,0},
                                {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
                                {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,0,1,0},
                                {0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,0,1,0},
                                {0,1,0,0,1,0,2,2,2,0,2,2,0,0,2,0,2,0,1,2,2,0,1,0},
                                {0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,2,0,1,0},
                                {0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,0,1,0},
                                {0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,0,1,0},
                                {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
                                {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0}
                            };
                        break;
                        #endregion
                    }
                case 8:
                    {
                        #region
                        isCau = false;
                        size = new Vector2(24, 12);
                        map = new int[24, 12]
                            {
                                {2,0,0,0,0,0,0,0,0,0,0,1},
                                {2,0,0,1,1,1,1,1,1,0,0,1},
                                {2,0,0,1,0,0,0,0,1,1,1,1},
                                {2,0,0,1,0,0,0,0,0,0,0,0},
                                {0,0,0,1,0,0,1,1,1,1,1,1},
                                {0,1,1,1,0,0,1,0,0,0,0,1},
                                {0,1,0,0,0,0,1,0,2,2,0,1},
                                {0,1,1,1,1,1,1,0,2,2,0,1},
                                {0,0,0,0,0,0,0,0,0,0,0,1},
                                {0,1,1,1,1,1,1,1,1,0,0,1},
                                {0,1,0,0,0,0,0,0,1,0,0,1},
                                {0,1,0,0,0,1,1,1,1,0,0,1},
                                {0,1,2,2,0,1,0,0,0,0,0,1},
                                {0,1,2,2,2,1,0,0,0,0,0,1},
                                {0,1,2,2,1,1,0,0,0,0,0,1},
                                {0,1,2,2,0,1,1,1,1,1,1,1},
                                {0,1,0,0,0,0,0,0,0,0,0,0},
                                {0,1,0,0,0,0,0,1,1,1,1,0},
                                {0,1,0,0,0,0,0,1,0,0,1,0},
                                {0,1,1,1,1,1,1,1,0,0,1,0},
                                {0,0,0,0,0,0,0,0,0,0,1,0},
                                {0,0,0,0,0,0,0,0,0,0,1,0},
                                {1,1,1,1,1,1,1,1,1,1,1,0},
                                {0,0,0,0,0,0,0,0,0,0,0,0}
                            };
                        break;
                        #endregion
                    }
                case 9:
                    {
                        #region
                        isCau = false;
                        size = new Vector2(15, 25);
                        map = new int[15, 25]
                            {
                                {2,2,2,2,2,2,0,0,0,0,2,2,2,2,0,0,1,0,0,0,0,0,0,0,0},
                                {2,2,2,2,2,0,0,0,0,0,0,0,0,2,2,0,1,0,0,0,0,0,0,0,0},
                                {2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,2,0,0,0,0,0},
                                {2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,1,0,2,2,0,0,0,0,0},
                                {2,2,2,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,0,0,0,0,0},
                                {2,2,0,0,0,0,0,1,0,0,0,0,0,0,0,2,2,2,2,2,0,1,1,1,1},
                                {2,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,2,2,2,0,1,0,2,2},
                                {2,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,2,2,0,1,0,2,2},
                                {0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,2,0,1,0,2,2},
                                {0,0,0,0,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,0,2},
                                {0,0,0,0,1,0,0,0,2,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,2},
                                {1,1,1,1,1,0,0,0,2,2,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0},
                                {2,2,2,2,0,0,0,2,2,2,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0},
                                {2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
                                {2,2,2,2,2,2,2,2,2,2,2,2,0,2,0,0,1,0,0,0,0,0,0,0,0}
                            };
                        break;
                        #endregion
                    }
                case 10:
                    {
                        #region
                        isCau = false;
                        size = new Vector2(15, 25);
                        map = new int[15, 25]
                            {
                                {2,2,2,2,2,2,2,2,2,2,2,0,1,0,2,2,2,2,2,2,2,2,2,2,2},
                                {2,2,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,2,2},
                                {1,1,1,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,2,2},
                                {0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,2,2},
                                {2,2,0,0,1,2,2,2,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1},
                                {2,2,0,0,1,2,2,2,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0},
                                {2,2,0,0,1,2,2,2,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,2,2},
                                {2,2,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,2,2},
                                {2,2,0,0,1,0,0,0,0,0,0,0,0,0,1,2,2,2,2,0,1,0,0,2,2},
                                {2,2,0,0,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,1,0,0,2,2},
                                {2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0,1,0,0,2,2},
                                {0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,2,2},
                                {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,2,2},
                                {2,2,2,2,2,2,2,2,2,2,2,0,1,0,2,2,2,2,2,2,2,2,2,2,2},
                                {2,2,2,2,2,2,2,2,2,2,2,0,1,0,2,2,2,2,2,2,2,2,2,2,2}
                            };
                        break;
                        #endregion
                    }
                default:
                    {
                        size = MapFolder.Map.SizeOfMatrix;
                        map = new int[(int)size.X, (int)size.Y];
                        for (int i = 0; i < (int)size.X; i++)
                        {
                            for (int j = 0; j < (int)size.Y; j++)
                            {
                                if (MapFolder.Map.matrix[i, j] == 0) map[i, j] = 1;
                                else if (MapFolder.Map.matrix[i, j] == 1) map[i, j] = 0;
                                else map[i, j] = 2;
                            }
                        }
                        break;
                    }
            }
        }//ok
        public void setLevel(int level)
        {
            this.level = level;
        }
        public int getLevel()
        {
            return level;
        }
        public int[,] getMap()
        {
            return map;
        }
        public Vector2 getSizeMap()
        {
            return sizeimages;
        }
        public Vector2 getSize()
        {
            return size;
        }
        public void Load(ContentManager content)
        {
            if (level <= 10)
            {
                int temp;
                if (level < 4) temp = 6;
                else if (level == 4 || level == 7 || level == 8) temp = 8;
                else if (level == 6) temp = 16;
                else if (level == 9 || level == 10) temp = 1;
                else temp = 9;
                for (int j = 0; j < temp; j++)
                {
                    images[j] = content.Load<Texture2D>("images/maps/map" + level.ToString() + "/m_" + j.ToString());
                }
            }
            else mapnew.Load(content);

            if (isCau)
            {
                cauimage = content.Load<Texture2D>("images/maps/caugo");
            }
            setSize();
        }
        public void Draw(SpriteBatch sprite)
        {
            scale = GamePage.scale;
            if (level < 4)
            {
                for (int i = 0; i < 6; i++)
                {
                    sprite.Draw(images[i], new Vector2((i % 3) * sizeImage.X * scale, (i / 3) * sizeImage.Y * scale) + GamePage.DoLech, null, Color.White, 0.0f, Vector2.Zero, scale * 4, SpriteEffects.None, 1.0f);
                }
            }
            else if (level == 4 || level == 7)
            {
                for (int i = 0; i < 8; i++)
                {
                    sprite.Draw(images[i], new Vector2((i % 4) * sizeImage.X * scale, (i / 4) * sizeImage.Y * scale) + GamePage.DoLech, null, Color.White, 0.0f, Vector2.Zero, scale * 4, SpriteEffects.None, 1.0f);
                }
                if (isCau)
                {
                    sprite.Draw(cauimage, new Vector2(400, 450) * scale + GamePage.DoLech, null, Color.White, 0.0f, Vector2.Zero, scale * 4, SpriteEffects.None, 1.0f);
                }
            }
            else if (level == 6)
            {
                for (int i = 0; i < 16; i++)
                {
                    sprite.Draw(images[i], new Vector2((i % 4) * sizeImage.X * scale, (i / 4) * sizeImage.Y * scale) + GamePage.DoLech, null, Color.White, 0.0f, Vector2.Zero, scale * 4, SpriteEffects.None, 1.0f);
                }
            }
            else if (level == 8)
            {
                for (int i = 0; i < 8; i++)
                {
                    sprite.Draw(images[i], new Vector2((i % 2) * sizeImage.X * scale, (i / 2) * sizeImage.Y * scale) + GamePage.DoLech, null, Color.White, 0.0f, Vector2.Zero, scale * 4, SpriteEffects.None, 1.0f);
                }
            }
            else if (level == 5)
            {
                for (int i = 0; i < 9; i++)
                {
                    sprite.Draw(images[i], new Vector2((i % 3) * sizeImage.X * scale, (i / 3) * sizeImage.Y * scale) + GamePage.DoLech, null, Color.White, 0.0f, Vector2.Zero, scale * 4, SpriteEffects.None, 1.0f);
                }
            }
            else if (level == 9 || level == 10)
            {
                sprite.Draw(images[0], new Vector2(0, 0) + GamePage.DoLech, null, Color.White, 0.0f, Vector2.Zero, scale * 4, SpriteEffects.None, 1.0f);
            }
            else
            {
                mapnew.Draw(sprite);
            }
        }
        public int countCellAvailable(int[,] map, Vector2 size)
        {
            int count = 0;
            for (int i = 0; i < (int)size.X; i++)
            {
                for (int j = 0; j < (int)size.Y; j++)
                {
                    if (map[i, j] == 0) count++;
                }
            }
            return count;
        }
        public string XacDinhHuong()
        {
            if (level == 0 || level == 1 || level == 4 || level == 7 || level == 8) return "Bottom";
            else if (level == 2) return "Left";
            else if (level == 3 || level == 5) return "Right";
            else if (level == 6) return "Top";
            return "Right";
        }//ok
        public string XacDinhRe(int level, Vector2 index, string huong)
        {
            setLevel(level);
            rand = new Random();
            switch (this.level)
            {
                case 0: break;
                case 1:
                    {
                        if (index.X == 2 && index.Y == 10) return "Bottom";
                        break;
                    }
                case 2:
                    {
                        if (index.X == 8 && index.Y == 20)
                        {
                            if (rand.Next(100) % 2 == 0) return "Left";
                            else return "Bottom";
                        }
                        else if (index.X == 8 && index.Y == 11)
                        {
                            if (rand.Next(100) % 2 == 0) return "Left";
                            else return "Top";
                        }
                        else if (index.X == 8 && index.Y == 2)
                        {
                            return "Bottom";
                        }
                        break;
                    }
                case 3:
                    {
                        if (index.X == 6 && index.Y == 3)
                        {
                            if (rand.Next(100) % 2 == 0) return "Top";
                            else return "Bottom";
                        }
                        else if (index.X == 6 && index.Y == 17)
                        {
                            return "Right";
                        }
                        break;
                    }
                case 4: break;
                case 5: break;
                case 6:
                    {
                        if (huong.Equals("Top") && ((index.X == 19 && index.Y == 8) || (index.X == 19 && index.Y == 15)))
                        {
                            if (rand.Next(100) % 2 == 0) return "Right";
                            else return "Left";
                        }
                        else if (index.X == 4 && index.Y == 11)
                        {
                            return "Bottom";
                        }
                        break;
                    }
                case 7:
                    {
                        if (index.X == 7 && index.Y == 18) return "Right";
                        break;
                    }
                case 8:
                    {
                        if (index.X == 14 && index.Y == 5) return "Left";
                        break;
                    }
                case 9: break;
                case 10: break;
                default:
                    {
                        return mapnew.XacDinhRe(level, index, huong);
                    }
            }
            return huong;
        }
        public Vector2 getBeGin()
        {
            rand = new Random();
            Vector2 temp;
            switch (level)
            {
                case 0:
                    {
                        temp = new Vector2(0, 2);
                        break;
                    }
                case 1:
                    {
                        if (rand.Next(100) % 2 == 0) temp = new Vector2(0, 2);
                        else temp = new Vector2(0, 18);
                        break;
                    }
                case 2:
                    {
                        if (rand.Next(100) % 2 == 0) temp = new Vector2(1, 23);
                        else temp = new Vector2(8, 23);
                        break;
                    }
                case 3:
                    {
                        temp = new Vector2(6, 0);
                        break;
                    }
                case 4:
                    {
                        temp = new Vector2(0, 3);
                        break;
                    }
                case 5:
                    {
                        temp = new Vector2(2, 0);
                        break;
                    }
                case 6:
                    {
                        if (rand.Next(100) % 2 == 0) temp = new Vector2(23, 8);
                        else temp = new Vector2(23, 15);
                        break;
                    }
                case 7:
                    {
                        if (rand.Next(100) % 2 == 0) temp = new Vector2(0, 4);
                        else temp = new Vector2(0, 22);
                        break;
                    }
                case 8:
                    {
                        if (rand.Next(100) % 2 == 0) temp = new Vector2(0, 11);
                        else temp = new Vector2(22, 0);
                        break;
                    }
                case 9:
                    {
                        if (rand.Next(100) % 2 == 0) temp = new Vector2(11, 0);
                        else temp = new Vector2(0, 16);
                        break;
                    }
                case 10:
                    {
                        if (rand.Next(100) % 2 == 0) temp = new Vector2(2, 0);
                        else temp = new Vector2(0, 12);
                        break;
                    }
                default:
                    {
                        temp = mapnew.getBegin();
                        break;
                    }
            }
            return temp;
        }//ok
        public void setSize()
        {
            switch (level)
            {
                case 0:
                    {
                        sizeImage = new Vector2(768, 640);
                        sizeimages = new Vector2(sizeImage.X * 3, sizeImage.Y * 2);
                        break;
                    }
                case 1:
                    {
                        sizeImage = new Vector2(896, 768);
                        sizeimages = new Vector2(sizeImage.X * 3, sizeImage.Y * 2);
                        break;
                    }
                case 2:
                    {
                        sizeImage = new Vector2(1024, 768);
                        sizeimages = new Vector2(sizeImage.X * 3, sizeImage.Y * 2);
                        break;
                    }
                case 3:
                    {
                        sizeImage = new Vector2(896, 896);
                        sizeimages = new Vector2(sizeImage.X * 3, sizeImage.Y * 2);
                        break;
                    }
                case 4:
                    {
                        sizeImage = new Vector2(736, 896);
                        sizeimages = new Vector2(sizeImage.X * 4, sizeImage.Y * 2);
                        break;
                    }
                case 6:
                    {
                        sizeImage = new Vector2(768, 768);
                        sizeimages = new Vector2(sizeImage.X * 4, sizeImage.Y * 4);
                        break;
                    }
                case 7:
                    {
                        sizeImage = new Vector2(768, 768);
                        sizeimages = new Vector2(sizeImage.X * 4, sizeImage.Y * 2);
                        break;
                    }
                case 8:
                    {
                        sizeImage = new Vector2(768, 768);
                        sizeimages = new Vector2(sizeImage.X * 2, sizeImage.Y * 4);
                        break;
                    }
                case 9:
                case 10:
                    {
                        sizeImage = new Vector2(3200, 1920);
                        sizeimages = new Vector2(3200, 1920);
                        break;
                    }
                default:
                    {
                        sizeImage = new Vector2(0, 0);
                        sizeimages = new Vector2(size.Y * 128, size.X * 128);
                        break;
                    }
            }
        }
    }
}
